// const scpClient = require("scp2");
// const ora = require("ora");
// const serverConfigs = require("./config");
import ora from "ora";
import scpClient from "scp2";
import serverConfigs from "./config.mjs";
const env = process.argv[2];

function deploy() {
  if (!env) { 
    console.log(`请输入你要部署的环境`)
    return;
  }
  const serverConfig = serverConfigs[env]
  if (!serverConfig) {
    console.log(`找不到${env}的配置文件!`);
    return;
  }
  const spinner = ora(`正在部署到${serverConfig.name}环境\n`)
  spinner.start();
  scpClient.scp("./dist",serverConfig,function (err) {
    spinner.stop()
    if (err) {
      console.log('  发布失败.\n')
      throw err
    } else {
      console.log('  Success! 成功部署到服务器! \n')
    }
  })
}

deploy()
// console.log();
// console.log(process.env);
